<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">  
  <title>订单列表</title>
 </head>
 <body>
 
 <?php
  require_once('inc_admin.php');

  connect();
  //编写sql语句
  $sql = "select a1.*,a2.zqyusername,a3.zqyitemname from zqyorders a1 left join zqyuser a2 on a1.zqyuserid=a2.zqyid left join zqyproduct a3 on a1.zqyitemid=a3.zqyid ";
  //表连接的时候注意两个表里面有同名称的列，再传参数的时候会出问题。  
  $result = fetch_array($sql); 
   
 ?>
 <center><h3>订单列表</h3></center>
 <table align="center" width="80%" border=1> 
 <tr>
   <th>订单ID</th>
   <th>用户名称</th>
   <th>产品名称</th>
   <th>数量</th>
   <th>订单时间</th>
   <th>支付金额</th>
   <th>订单状态</th>



   <th>操作</th>   
   
 </tr>

 <?php
  foreach ($result as $row) {
   echo '<tr>';
   echo '<td>'.$row['zqyid'].'</td>';
   echo '<td>'.$row['zqyusername'].'</td>'; 
   echo '<td>'.$row['zqyitemname'].'</td>'; 
   echo '<td>'.$row['zqymnum'].'</td>'; 
   echo '<td>'.$row['zqyordertime'].'</td>'; 
   echo '<td>'.$row['zqypay'].'</td>'; 
   if($row['zqyorderstate']=='0')
  {
    $row['zqyorderstate']='待发货';
  }
     if($row['zqyorderstate']=='1')
  {
    $row['zqyorderstate']='已取消';
  }
     if($row['zqyorderstate']=='2')
  {
    $row['zqyorderstate']='已发货';
  }
  echo '<td>'.$row['zqyorderstate'].'</td>'; 
  
   
   echo '<td><a href="zqyorderEditForm.php?id='.$row['zqyid'].' ">修改</a> | 
   <a href="zqycanelorder.php?id='.$row['zqyid'].' ">取消</a> | |
     <a href="zqydelorder.php?id='.$row['zqyid'].'" onClick="return confirm(\'确定要删除订单吗？\');">删除</a>
    | <a href="zqydeliver.php?id='.$row['zqyid'].' ">发货</a> 



   </td>';
   echo '</tr>';  
  }
  echo '</table>';  
  $totalrows = count($result);
  echo "<table align='center'><tr><td>共有{$totalrows}条记录</td></tr></table>";   
 ?>
 
 </body>
</html>